home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / db3tips4.arc / DB3DATES next >
Encoding:
Text File  |  1987-01-03  |  2.3 KB  |  56 lines

  1.                         dBASE by the Week
  2.         (PC Magazine Vol 6 No 2 Jan 27, 1987 Power User)
  3.  
  4.      Many reports need to be summarized by the WEEK OF, so a way is
  5. needed to convert dBASE III data fields to their preceding Sunday.
  6. Instead of using a complicated program, the method turns out to be:
  7.  
  8. weekof=date+1-DOW(date)
  9.  
  10.      Editor's Note:  To produce a report by WEEK OF, start with:
  11.  
  12. INDEX ON date+1-DOW(date)
  13.  
  14. Then modify the report .FRM file to use the same algorithm for the
  15. Subtotal Field.  If your week starts on Sunday, just use:
  16.  
  17. date+2-DOW(date)
  18.  
  19.      Notice, however, that the INDEX ON command will not differentiate
  20. between a Monday and a Friday: the algorithm converts them all to
  21. Sunday.  If you are producing a summary report, this won't matter,
  22. but a detailed listing will be in WEEK OF order, with Thursdays and
  23. Mondays all jumbled up.
  24.      If you need a detailed report in actual date order, you can take
  25. two different approaches.  One way is to SORT the file on date first,
  26. then do the INDEX.  The other approach requires a more complicated
  27. INDEX ON command.  The index must use the WEEK OF algorithm as its
  28. dominant element and then differentiate between weekdays.  Because the
  29. WEEK OF algorithm is a Date-type variable, however, you unfortunately
  30. can't concatenate character strings or add numerics to it, which is a
  31. pain in the neck.
  32.      The INDEX ON command suggested below converts the WEEK OF Sundays
  33. into an integer and then adds the day-of-the-week as a trailing
  34. decimal:
  35.  
  36. x="date+1-DOW(date)"
  37. INDEX ON 100*MONTH(&x)+DAY(&x)+DOW(date)/10 TO <filename>
  38.  
  39. This INDEX ON formula produces indexable values in the form:
  40.  
  41. Sun, 1/05/86 =105.1
  42. Mon, 1/06/86 =105.2
  43. Sun, 1/12/86 =112.1
  44. Mon, 1/13/86 =112.3
  45.  
  46. Whether you SORT first or use this longer INDEX ON command, the
  47. Subtotal Formula in your .FRM file remains the same.
  48.      If you enter "WEEK OF:" as the Subtotal Heading and use the
  49. following as the Subtotal Expression:
  50.  
  51. CDOW(date+1-DOW(date))+', '+DTOC(date+1-DOW(date))
  52.  
  53. you can create an attractive, complete Subtotal Heading that displays
  54. in the format:  "WEEK OF: Sunday, January 6, 1986."
  55.  
  56.